
uniform mat4 mWorldViewProj;
uniform mat4 mInvWorld;
uniform mat4 mTransWorld;

uniform float mTime;
uniform vec4 mColor;


void main(void)
{
	const float puffSpeed = 0.5;
	const int frames = 128;
	const int cols = 15;
	const float w = 16.0 / 256.0;
	const float h = 16.0 / 256.0;
	const float gap = 1.0 / 256.0;
	const float tw = w + gap;
	const float th = h + gap;

	float rnd = gl_Normal.z;

	float frame = mod(floor((mTime * puffSpeed + rnd) * float(frames)), float(frames));
	float col = mod(float(frame), float(cols));
	float row = floor(frame / float(cols));
	vec4 uv = gl_MultiTexCoord0;
	uv.x = col * tw + uv.x * w;
	uv.y = row * th + uv.y * h;
	

	vec4 pos = mWorldViewProj * gl_Vertex;
	vec4 corner = vec4(gl_Normal.xy, 0.0, 0.0);
	float sz = clamp(pos.z, 0.17, 0.3);			// max, min size (divisor tweak)
	corner /= vec4(sz, sz, 1.0, 1.0);
	pos += corner;

	gl_Position = pos;

	gl_FrontColor = vec4(mColor.xyz, mColor.w * smoothstep(0.5, 0.7, pos.w));

	gl_TexCoord[0] = uv;
}
